﻿Imports System.IO
Imports MiscUtil.Conversion
Imports SWE.DBAdapter.IO

Public Class DBAdapter
    Implements SWE.Contracts.IDB
    Private m_Filename As String


    Public Sub New(ByVal Filename As String)
        m_Filename = Filename
    End Sub

    Public Function CreateRecord(ByVal cat As Integer, ByVal data() As String) As Integer Implements Contracts.IDB.CreateRecord

    End Function

    Public Sub DeleteRecord(ByVal cat As Integer, ByVal num As Integer, ByVal Lock As Long) Implements Contracts.IDB.DeleteRecord

    End Sub

    Public Function FindByCriteria(ByVal cat As Integer, ByVal criteria() As String) As Integer() Implements Contracts.IDB.FindByCriteria

    End Function

    Public Function Lock(ByVal cat As Integer, ByVal num As Integer) As Long Implements Contracts.IDB.Lock

    End Function

    Public Function ReadNames(ByVal cat As Integer) As String() Implements Contracts.IDB.ReadNames

    End Function

    Public Function ReadNumberOfCategories() As Integer Implements Contracts.IDB.ReadNumberOfCategories
        Dim NumberOfCategories As Integer

        NumberOfCategories = 0

        Try
            Using Filestream As New FileStream(m_Filename, FileMode.Open)

                Using Binaryreader As New EndianBinaryReader(Filestream)
                    Dim OffsetOfFirstCategorie As Integer = Binaryreader.ReadInt32Endian(4)

                    NumberOfCategories = (OffsetOfFirstCategorie - 4) / 4
                End Using

            End Using
        Catch ex As Exception

        End Try

        Return NumberOfCategories
    End Function

    Public Function ReadNumberOfRecords(ByVal cat As Integer) As Integer Implements Contracts.IDB.ReadNumberOfRecords

    End Function

    Public Function ReadRecord(ByVal cat As Integer, ByVal num As Integer) As String() Implements Contracts.IDB.ReadRecord

    End Function

    Public Sub Unlock(ByVal cat As Integer, ByVal num As Integer, ByVal Lock As Long) Implements Contracts.IDB.Unlock

    End Sub

    Public Sub UpdateRecord(ByVal cat As Integer, ByVal num As Integer, ByVal data() As String, ByVal Lock As Long) Implements Contracts.IDB.UpdateRecord

    End Sub
End Class
